package org.snail.other.controller;

import lombok.extern.log4j.Log4j;
import org.snail.chat.service.impl.ChatServiceImpl;
import org.snail.common.dingding.auth.AuthHelper;
import org.snail.common.dingding.chat.ChatHelper;
import org.snail.common.xmlBean.XmlToDocHolder;
import org.snail.dept.mapper.DepartmentMapper;
import org.snail.employee.bean.AddressDO;
import org.snail.employee.mapper.AddressMapper;
import org.snail.exception.JsonResult;
import org.snail.other.bean.GroupDO;
import org.snail.other.mapper.GroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@Log4j
public class TestController {
//    @Autowired
//    public TestServiceImpl testService;
    @Autowired
    private GroupMapper groupMapper;
    @Autowired
    private XmlToDocHolder xmlToDocHolder;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private ChatServiceImpl chatService;
    @Autowired
    private AddressMapper addressMapper;

//    @RequestMapping("/test")
//    @ResponseBody
//    public JsonResult testDemo() throws Exception {
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setData(testService.test());
//        return jsonResult;
//    }

    @RequestMapping("/testCreateChat")
    @ResponseBody
    public JsonResult testCreateChat() throws Exception {
        JsonResult jsonResult = new JsonResult();
        for(int i=61;i<=110;i++){
            List<String> useridlist  = new ArrayList<String>();
            //龚鹤宝userId
            useridlist.add("045552223440544979");
            //思思userId
            useridlist.add("153204375129212779");
            //夏阳userId
            useridlist.add("1301625569745220");
            useridlist.add("1301625569745220");
            String chatid = ChatHelper.createChat(AuthHelper.getAccessToken(),"bug小分队"+i,"1301625569745220",  useridlist);
            GroupDO groupDO = new GroupDO();
            groupDO.setGroupName("bug小分队"+i);
            groupDO.setChatId(chatid);
            groupDO.setGroupType(2);
            groupMapper.saveGroup(groupDO);
            jsonResult.setData(chatid);
        }

        return jsonResult;
    }

    @RequestMapping("/testXmlToDocHolder")
    @ResponseBody
    public JsonResult testXmlToDocHolder() throws Exception {
        JsonResult jsonResult = new JsonResult();
        Map map = xmlToDocHolder.xmlTransToBean();
        jsonResult.setData(jsonResult);
        return jsonResult;
    }

    @RequestMapping("/chatCreateOrUpdateChain")
    @ResponseBody
    public JsonResult chatCreateOrUpdateChain() throws Exception {
        JsonResult jsonResult = new JsonResult();
        chatService.sychronizeUserDepatChat();
        return jsonResult;
    }

    @RequestMapping("/testMyGit")
    @ResponseBody
    public JsonResult testMygit() throws Exception {
        JsonResult jsonResult = new JsonResult();
        log.error("测试获取ghb的git代码");
        return jsonResult;
    }

    @RequestMapping("testSQL")
    @ResponseBody
    public JsonResult testSQL(){
        JsonResult jsonResult = new JsonResult();
//      List<String> ids = departmentMapper.findWorknumList();

        List<String> userIdList = new ArrayList<>();
        userIdList.add("1111111");
        userIdList.add("2222222");
//      departmentMapper.saveDeptUserList(11L,userIdList);

        departmentMapper.deletDeptUserList(11L,userIdList,new Date());
        return jsonResult;
    }

    @RequestMapping("insertAddress")
    @ResponseBody
    public JsonResult testInsertAddress(){
        JsonResult jsonResult = new JsonResult();
        List<String> list = new ArrayList<>();
        list.add("userIdtest1");
        list.add("userIdtest2");
        AddressDO addressDO = new AddressDO();
        addressDO.setEmpId(111);
        addressMapper.insertAddress(addressDO);
        List<Long> ids = addressMapper.findGroupIds();
        addressMapper.insertBatchAddresssBydeptIdAndUserids(list,100L,new Date());
        return jsonResult;
    }

}
